package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.EmployeeDTO;
import com.sky.dto.PasswordEditDTO;
import com.sky.entity.Employee;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     *
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

    /**
     * 查找原先密码
     *
     * @param id
     * @return
     */
    @Select("select password from employee where id=#{id}")
    String findOldPassword(Long id);

    /**
     * 修改密码
     *
     * @param passwordEditDTO
     */
    @Update("update employee set password=#{password} where id=#{id} ")
    void updatePassword(PasswordEditDTO passwordEditDTO);

    /**
     * 分页查询
     *
     * @param name
     * @return
     */
    Page<Employee> findByPage(String name);

    /**
     * 新增员工
     *
     * @param employeeDTO
     */
    void addEmployee(EmployeeDTO employeeDTO);

    /**
     * 根据查询
     *
     * @param id
     */
    @Select("select id,username,name,phone,sex,id_number from employee where id=#{id}")
    EmployeeDTO findById(Integer id);

    /**
     * 修改员工信息`
     *
     * @param employeeDTO
     */
    @Update("update employee set name=#{name},username=#{username},id_number=#{idNumber},phone=#{phone},sex=#{sex},update_time=now() where id=#{id}")
    void updateEmployeeInfo(EmployeeDTO employeeDTO);

    /**
     * 启用、禁用员工账号
     * @param status
     * @param id
     */
    @Update("update employee set status=#{status} where id=#{id}")
    void updateEmployeeStatus(Integer status, Integer id);
}
